export function toast(title,icon='none',duration=2000){
	uni.showToast({
		title,
		icon,
		duration
	})
}

export function modal(title,content,func_success=() => {},func_cancel=() => {}){
	uni.showModal({
		title,
		content,
		success: (res) => {
			if(res.confirm){
				func_success()
			} else {
				func_cancel()
			}
		}
	})
}

export function loading(title){
	uni.showLoading({
		title
	})
}

export function routeUrl(url,type='navigateTo'){
	switch(type){
		case 'navigateTo':
			uni.navigateTo({
				url
			})
			break
		case 'redirectTo':
			uni.redirectTo({
				url
			})
			break
		case 'switchTab':
			uni.switchTab({
				url
			})
			break
	}
}

export function deepClone(ele){
	return JSON.parse(JSON.stringify(ele))
}

// 字符串转十六进制
export function strToHex(str){
	let hexStr = "";
	for (let i = 0; i < str.length; i++) {
	    let charCode = str.charCodeAt(i);
	    hexStr += charCode.toString(16).padStart(2, '0');
	}
	return hexStr
}

// 数组转对象
export function convertArr2Obj(arr, key) {
	return arr.reduce((obj, v) => {
		obj[v[key]] = v
		return obj
	}, {})
}